class Shop < ActiveRecord::Base
  has_many :categors
  has_many :staffs
  belongs_to :town, :autosave => true
  has_and_belongs_to_many :desires
  has_attached_file :photo, :url => "/:attachment/:class/:style_:id.:extension",
    :path => ":rails_root/public/:attachment/:class/:style_:id.:extension", :default_url => "/images/shop.jpg"
  validates_attachment_presence :photo, :message  => I18n.t("errors.messages.attachment.presence")
  validates_attachment_size :photo, :less_than => 50.kilobytes, :message => I18n.t("errors.messages.attachment.size"), :allow_nil => true
  validates_attachment_content_type :photo, :content_type => ['image/jpeg'], :message => I18n.t("errors.messages.attachment.content_type"), :allow_nil => true
  validates :name, :length => {:within => 3..30}
  validates :description, :length => {:within => 3..305}
  validates :workhours, :length => {:within => 3..45}
  validates :kitchenhours, :length => {:within => 3..45}
  validates :kitchen, :length => {:within => 3..45}
  validates :phone, :length => {:within => 7..12}
  validates :mobile, :length => {:within => 7..12}
  validates :address, :length => {:within => 3..45}
  validates :time, :length => {:within => 3..45}
  validates_inclusion_of :status, :in => %w[banned approved]
  
  def add_order_categor order_categor
    @order_categors = [] if @order_categors.nil?
    @order_categors << order_categor
  end

  def get_order_categors
    @order_categors
  end

end
